package com.itheima.tlias.config;

import com.itheima.tlias.interceptors.HelloInterceptor;
import com.itheima.tlias.interceptors.LoginCheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 * @author
 * @version 1.0.1
 * @date 2023-04-11 12:20:44
 */
//@Configuration代表当前类是一个配置类
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 注入拦截器
     */
    @Autowired
    private HelloInterceptor helloInterceptor;

    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        registry.addInterceptor(helloInterceptor)
                //指定拦截的资源
                .addPathPatterns("/depts/**", "/emps/**")   //拦截的资源
                .excludePathPatterns("/login", "/index");   //放行的资源

        registry.addInterceptor(loginCheckInterceptor)
                 //需要拦截的资源
                .addPathPatterns("/**")
                 //不需要拦截的资源
                .excludePathPatterns("/login");
    }
}
